/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.RoleEntity;
import javax.ejb.Stateless;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;

/**
 *
 * @author thanhle
 */
@Stateless
public class RoleEntityFacade extends AbstractFacade<RoleEntity> {

    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public RoleEntityFacade() {
        super(RoleEntity.class);
    }

    public RoleEntity findRole(String roleName) {
        try {
            Query query = (Query) em.createQuery(
                    "SELECT r FROM roles r WHERE r.roleName = '" + roleName + "'");
            RoleEntity result = (RoleEntity) query.getSingleResult();
            return result;
        } catch (NoResultException e) {
            return null;
        }
    }
}
